package com.efivestar.idm.api.service;

import com.efivestar.idm.api.domain.DeviceDomain;
import com.efivestar.idm.api.repository.DeviceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class DeviceService {

    Logger logger = LoggerFactory.getLogger(DeviceService.class);


    @Autowired
    private DeviceMapper deviceMapper;


    /**
     * 更新电量.
     * @param deviceId
     * @param power
     */
    public void updatePower(String deviceId, int power) {
        DeviceDomain deviceDomain = DeviceDomain.builder().deviceId(deviceId).power(power).heartTime(new Date()).build();
        deviceMapper.updateByPrimaryKeySelective(deviceDomain);
    }

    /**
     * 更新电量和撤防状态.
     * @param deviceId
     * @param power
     */
    public void updatePowerAndDefenseStatus(String deviceId, int power, int defenseStatus) {
        DeviceDomain deviceDomain = DeviceDomain.builder().deviceId(deviceId).power(power).defenseStatus(defenseStatus).heartTime(new Date()).build();
        deviceMapper.updateByPrimaryKeySelective(deviceDomain);
    }

}



